/************************************   

DESCRIPTION: This program standardizes and reshapes the block estimates. 
 The final .dta will be used in an r script for inclusion in the paper.

Datasets used:
 (1) malebetaDiab_overall
 (2) fembetaDiab_overall
 (3) malebetaHyp_overall
 (4) fembetaHyp_overall
 (5) maleblockDeath_overall
 (6) femblockDeath_overall

Datasets created:
 (1) mdo
 (2) fdo
 (3) mho
 (4) fho
 (5) mao
 (6) fao
 (7) blockTable

 ************************************/   

clear all
   
set more off
capture log close
clear all

set matsize 10000

*Male diabetes overall mdo
	use malebetaDiab_overall
		keep block shareblk beta_ outcome
		capture rename shareblk shareblk_mD 
		capture rename beta_ beta_md
		reshape wide share* beta , i(block) j(outcome) str
	save mdo, replace
	clear

*feMale diabetes overall mdo
	use fembetaDiab_overall
		keep block shareblk beta_ outcome
		capture rename shareblk shareblk_fD 
		capture rename beta_ beta_fD
		reshape wide share* beta , i(block) j(outcome) str
	save fdo, replace
	clear

*Male hypertension overall mho
	use malebetaHyp_overall
		keep block shareblk beta_ outcome
		capture rename shareblk shareblk_mH
		capture rename beta_ beta_mH
		reshape wide share* beta , i(block) j(outcome) str
	save mho, replace
	clear 

*FeMale hypertension overall mho
	use fembetaHyp_overall
		keep block shareblk beta_ outcome
		capture rename shareblk shareblk_fH
		capture rename beta_ beta_fH
		reshape wide share* beta , i(block) j(outcome) str
	save fho, replace
	clear 

*feMale death overall mao
	use femblockdeath_overall
		keep block shareblk beta_ outcome
		capture rename shareblk shareblk_fA
		capture rename beta_ beta_fA
		reshape wide share* beta , i(block) j(outcome) str
	save fao, replace
	clear 
 
*Male death overall mao
	use maleblockdeath_overall
		keep block shareblk beta_ outcome
		capture rename shareblk shareblk_mA
		capture rename beta_ beta_mA
		reshape wide share* beta , i(block) j(outcome) str
	save mao, replace
	clear 


*Put it all together
	use mao 
		merge 1:1 block using fao
		drop _merge
		merge 1:1 block using fho
		drop _merge
		merge 1:1 block using mho
		drop _merge
		merge 1:1 block using fdo
		drop _merge
		merge 1:1 block using mdo
		drop _merge
	  
	  saveold ./blockTable.dta, version(12) replace
